package Operation;

import Book.BookList;

import java.util.Scanner;

public class ReturnBook implements IOPeration{
    @Override
    public void work(BookList books) {
        System.out.println("归还图书");
        System.out.println("请输入要归还的图书：");
        Scanner sc = new Scanner(System.in);
        String bookName = sc.nextLine();

        for (int i = 0; i < books.getUsedSize(); i++) {
            //先看存不存在
            if (books.getBook(i).getName().equals(bookName)){
                //存在
                //看是否被借出
                if((books.getBook(i).isBorrowed())){
                    //已借出
                    books.getBook(i).setBorrowed(false);
                    System.out.println("归还成功！");
                    return;
                }else{
                    System.out.println("此书没有借出。");
                    return;
                }
            }
        }
        System.out.println("没有借阅出此书.....");

    }
}
